package util;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Map;
import java.util.TreeMap;

public final class PropertyMgr {

    static Map<String, String> propertyMap;
    static Map<String, String> conPropertyMap;
    
    public static void loadProperty()
	{
		
		if(propertyMap != null)
			return;
		
		propertyMap = new TreeMap<String, String>();
        BufferedReader in;

        try {
        
			in = new BufferedReader(new FileReader("resources/property.tab"));

        String line = "";

			while ((line = in.readLine()) != null) {
			    String parts[] = line.split("=");
			    propertyMap.put(parts[0], parts[1]);
			}

        in.close();
        
		in = new BufferedReader(new FileReader("resources/connections.tab"));

        line = "";

			while ((line = in.readLine()) != null) {
			    String parts[] = line.split("=");
			    propertyMap.put(parts[0], parts[1]);
			}

        in.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
	
    public static String getValue(String property)
	{
		if (property == null||property.isEmpty())
			property = "default";

		//return propertyMap.get(property) == null ?propertyMap.get("default"):propertyMap.get(property);
		return propertyMap.get(property);
	}
	
    public static String getConValue(String property)
	{
		if (property == null||property.isEmpty())
			property = "default";

		//return propertyMap.get(property) == null ?propertyMap.get("default"):propertyMap.get(property);
		return propertyMap.get(property);
	}
	
}
